package RemoteServerTest;

import java.rmi.RemoteException;
import java.sql.Date;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import Po.Credits;
import Po.Discount;
import Po.Equivalent;
import Po.Manager;
import Po.Message;
import Po.Result;
import RemoteServer.GeneralManagerServer;
import RemoteServerInterface.GeneralManagerServerInterface;

public class GeneralManagerServerTest {

	GeneralManagerServerInterface test;
	@Before
	public void setUp() throws Exception {
		test=new GeneralManagerServer();
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public final void testGmLogin() throws RemoteException {
		Manager m = test.GeneralManagerLogin(new Manager("whk", "111111"));
		Assert.assertTrue(m.name.equals("whk"));
		Assert.assertTrue(m.password.equals("111111"));
	}
	
	@Test
	public final void testPresent() throws RemoteException {
		Message m  = test.presentPromotion(new Discount(null,null,null,null,1,0), 1, 1);
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@SuppressWarnings("deprecation")
	@Test
	public final void testAddDis() throws RemoteException {
		Message m  = test.addDiscountPromotion(new Discount(new Date(123, 1,1),
						new Date(123, 1,1),new Date(123, 1,1),new Date(123, 1,1), 0, 0));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testAddE() throws RemoteException {
		@SuppressWarnings("deprecation")
		Message m  = test.addEquivalentPromotion(new Equivalent(new Date(123, 1,1),
						new Date(123, 1,1),new Date(123, 1,1),new Date(123, 1,1), 33, 0, 0));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testGetRanks() throws RemoteException {
		int[] ranks = test.getRanks();
		Assert.assertTrue(ranks.length == 2);
	}
	
	@Test
	public final void testMD() throws RemoteException {
		@SuppressWarnings("deprecation")
		Message m  = test.modifyDiscountPromotion(new Discount(new Date(123, 1,1),
						new Date(123, 1,1),new Date(123, 1,1),new Date(123, 1,1), 0, 1));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@SuppressWarnings("deprecation")
	@Test
	public final void testME() throws RemoteException {
		Message m  = test.modifyEquivalentPromotion(new Equivalent(new Date(123, 1,1),
					new Date(123, 1,1),new Date(123, 1,1),new Date(123, 1,1), 33, 0, 1));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testMC() throws RemoteException {
		Credits c  = new Credits();
		c.creditsToMoneyRate = 0;
		c.moneyToCreditsRate = 0;
		Message m  = test.modeifyCredits(c);
		Assert.assertTrue(m.result == Result.Success);
	}
}
